package com.ews.onlineexchange.service;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;

import com.ews.onlineexchange.model.BestTradeEvaluation;

@Named
public class BestTradeEvaluationService implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Inject
	EntityManager entityManager;
	private final static String GET_LIST_BY_TRADE_HQL = ""
			+ " select ev" 
			+ " from BestTradeEvaluation ev "
			+ " where ev.trade.id = :tradeId " ;
	public List<BestTradeEvaluation> getBestTradeEvaluationListByTrade (String tradeId){
		return entityManager.createQuery(GET_LIST_BY_TRADE_HQL).setParameter("tradeId", tradeId).getResultList();
	}
	
	private String GET_BESTTRADEEVAL_BY_TRADEID_AND_REQID = ""
			+ " select count(id)" 
			+ " from BestTradeEvaluation ev "
			+ " where ev.trade_id= :tradeId " 
			+ " and ev.requirementdefination_id = :reqId ";
	public BigDecimal getBestTradeEvaluationByTradeAndReq (String tradeId,String reqId){
		return (BigDecimal)entityManager.createNativeQuery(GET_BESTTRADEEVAL_BY_TRADEID_AND_REQID)
				.setParameter("tradeId", tradeId)
				.setParameter("reqId", reqId).getSingleResult();
	}
}
